package name.ekr.assetguide.domain;

import name.ekr.assetguide.data.DataLogger;
import name.ekr.assetguide.data.PriceIterator;

import static name.ekr.assetguide.Math.*;


public class RebalancedPortfolio extends Portfolio {
    public RebalancedPortfolio(
            PriceIterator iterator,
            DataLogger logger,
            double usdShare, double goldShare, double silverShare, double sharesShare, double bondsShare, double rurShare) {

        super(iterator, logger, usdShare, goldShare, silverShare, sharesShare, bondsShare, rurShare);
    }

    @Override
    public String toString() {
        return super.toString() + ";rebalanced";
    }

    @Override
    protected void everyPeriodHandler(AssetsPrice prices) {
        super.everyPeriodHandler(prices);
        rebalanceAssets(prices);
    }

    private void rebalanceAssets(AssetsPrice prices){
        nUSD = price * usdShare / prices.getUsdPrice();
        nBND = price * bondsShare / prices.getBondsPrice();
        nGLD = price * goldShare / prices.getGoldPrice();
        nRUR = price * rurShare / prices.getRurPrice();
        nSHR = price * sharesShare / prices.getSharesPrice();
        nSLV = price * silverShare / prices.getSilverPrice();
    }
}
